#ifndef __TILE_H__
#define __TILE_H__

#include <QGraphicsItem>
#include <QGraphicsSceneMouseEvent>
#include <QPixmap>
#include <QString>
#include <QRectF>
#include <QPainter>

#include <iostream>
using std::cout;
using std::endl;

#include "Toolbar.h"	// nodig om te weten welke vorm ze krijgen

class Tile : public QGraphicsItem
{
public:
	 Tile(Toolbar* toolbar, qreal size, const QPixmap& pix, const QString& type)
		: m_toolbar(toolbar), m_size(size), m_pixmap(pix), m_type(type)
	 {
		this->setAcceptDrops(true);
	 }

     QRectF boundingRect() const
     {
         return QRectF(-m_size/2, -m_size/2, m_size, m_size);
     }

	 void mousePressEvent ( QGraphicsSceneMouseEvent * event )
	 {
		if ( m_toolbar && event->button() == Qt::LeftButton) 
        { 
			doUpdate();
		}
	 }

	 void doUpdate()
	 {
			m_pixmap = m_toolbar->currentPixmap();
			m_type = m_toolbar->currentString();
			update(m_size, m_size, m_size*2, m_size*2);
	 }

     void paint(QPainter *painter, const QStyleOptionGraphicsItem* , QWidget* )
     {
         painter->drawPixmap ( QRectF(-m_size/2, -m_size/2, m_size, m_size), m_pixmap, QRectF(0,0, m_pixmap.width(), m_pixmap.height()) );
     }

	const QString& getType() const { return m_type; }

private:
	Toolbar* m_toolbar;
	qreal m_size;
	QPixmap m_pixmap;
	QString m_type;	// serialize van vakje

};

#endif
